﻿<UserControl x:Class="BbsbWsGui.ItemsTab"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:gui="clr-namespace:BbsbWsGui"
                 mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <gui:ChildDescriptionFromBaseItemConverter x:Key="childDescriptionFromBaseItemConverter" />
        <Style x:Key="dataGridCellStyle" TargetType="{x:Type DataGridCell}">
            <Style.Setters>
                <Setter Property="BorderBrush" Value="Transparent" />
                <Setter Property="BorderThickness" Value="1" />
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="Foreground" Value="Black" />
            </Style.Setters>
            <Style.Triggers>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}},Path=IsSelected}" Value="True" />
                        <Condition Binding="{Binding Path=State}" Value="On" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="Control.Background" Value="DarkGreen" />
                        <Setter Property="Control.Foreground" Value="White" />
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}},Path=IsSelected}" Value="True" />
                        <Condition Binding="{Binding Path=State}" Value="Off" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="Control.Background" Value="DarkRed" />
                        <Setter Property="Control.Foreground" Value="White" />
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
                <MultiDataTrigger>
                    <MultiDataTrigger.Conditions>
                        <Condition Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type DataGridRow}},Path=IsSelected}" Value="True" />
                        <Condition Binding="{Binding Path=State}" Value="Unknown" />
                    </MultiDataTrigger.Conditions>
                    <MultiDataTrigger.Setters>
                        <Setter Property="Control.Background" Value="DarkBlue" />
                        <Setter Property="Control.Foreground" Value="White" />
                    </MultiDataTrigger.Setters>
                </MultiDataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="stateStyle">
            <Style.Setters>
                <Setter Property="Control.Background" Value="LightGoldenrodYellow" />
                <Setter Property="Control.Foreground" Value="Black" />
            </Style.Setters>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=State}" Value="Off">
                    <Setter Property="Control.Background" Value="PaleVioletRed" />
                    <Setter Property="Control.Foreground" Value="Black" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Path=State}" Value="On">
                    <Setter Property="Control.Background" Value="PaleGreen" />
                    <Setter Property="Control.Foreground" Value="Black" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid>
        <DataGrid Margin="27,17,87,56" x:Name="allItemsLst" IsReadOnly="True" AutoGenerateColumns="False" SelectionMode="Single" SelectionUnit="FullRow"
                  RowStyle="{StaticResource stateStyle}" CanUserSortColumns="True"
                  ItemsSource="{Binding}" CellStyle="{StaticResource dataGridCellStyle}"
            HeadersVisibility="Column" MouseDoubleClick="allItemsLst_MouseDoubleClick" GridLinesVisibility="Horizontal">
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Name" Width="150">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate DataType="BbsbService.Classes.BaseItem" >
                            <StackPanel Margin="10 10 10 0" Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=Name}">
                                    <TextBlock.ToolTip>
                                        <ToolTip>
                                            <TextBlock Text="{Binding Converter={StaticResource childDescriptionFromBaseItemConverter}}" HorizontalAlignment="Stretch" />
                                        </ToolTip>
                                    </TextBlock.ToolTip>
                                </TextBlock>
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Type">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate DataType="BbsbService.Classes.BaseItem" >
                            <StackPanel Margin="10 10 10 0" Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=TypeName}" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="State">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate DataType="BbsbService.Classes.BaseItem" >
                            <StackPanel Margin="10 10 10 0" Orientation="Horizontal">
                                <TextBlock Text="{Binding Path=State}" />
                            </StackPanel>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <Button Height="23" Margin="40,0,0,15" Name="addItemBtn" VerticalAlignment="Bottom" HorizontalAlignment="Left" Width="75" Click="addItemBtn_Click">Add</Button>
        <Button Height="23" Margin="149,0,206,15" Name="removeItemBtn" VerticalAlignment="Bottom" Click="removeItemBtn_Click">Remove</Button>
        <Button Height="23" Margin="0,0,97,15" Name="editItemBtn" VerticalAlignment="Bottom" HorizontalAlignment="Right" Width="75" Click="editItemBtn_Click">Edit</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,145,24,0" Name="testOnBtn" VerticalAlignment="Top" Width="35" Click="testOnBtn_Click">On</Button>
        <Button HorizontalAlignment="Right" Margin="0,196,24,0" Name="testOffBtn" Width="35" Height="23.38" VerticalAlignment="Top" Click="testOffBtn_Click">Off</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,95,24,0" Name="toggleButton" VerticalAlignment="Top" Width="35" Click="toggleButton_Click">TGL</Button>
        <Button Height="23" HorizontalAlignment="Right" Margin="0,17,24,0" Name="refreshList" VerticalAlignment="Top" Width="35" Click="refreshList_Click">Refresh</Button>
    </Grid>
</UserControl>
